﻿/*
* Copyright (c) 2010-2012 Tesla Engine Group
* 
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
* 
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
* 
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/


using System;
using Tesla.Math;

namespace Tesla.Content.Loaders.Model.Dxs {
    public struct DxsVertex {
        public int ID;
        public Vector3 Position;
        public Vector3 Normal;
        public Vector2 TextureCoordinate;
        public Vector2 LightMapCoordinate;
        public Color VertexColor;
        public int JointID;

        public DxsVertex(int vid, Vector3 position) {
            ID = vid;
            Position = position;
            Normal = Vector3.Zero;
            TextureCoordinate = Vector2.Zero;
            LightMapCoordinate = Vector2.Zero;
            VertexColor = Color.White;
            JointID = -1;
        }

        public DxsVertex(int vid, Vector3 position, Vector2 texCoord) {
            ID = vid;
            Position = position;
            Normal = Vector3.Zero;
            TextureCoordinate = texCoord;
            LightMapCoordinate = Vector2.Zero;
            VertexColor = Color.White;
            JointID = -1;
        }

        public DxsVertex(int vid, Vector3 position, Vector2 texCoord, Vector2 lightmapCoord) {
            ID = vid;
            Position = position;
            Normal = Vector3.Zero;
            TextureCoordinate = texCoord;
            LightMapCoordinate = lightmapCoord;
            VertexColor = Color.White;
            JointID = -1;
        }

        public DxsVertex(int vid, Vector3 position, Vector2 texCoord, Vector2 lightmapCoord, Color vertexColor) {
            ID = vid;
            Position = position;
            Normal = Vector3.Zero;
            TextureCoordinate = texCoord;
            LightMapCoordinate = lightmapCoord;
            VertexColor = vertexColor;
            JointID = -1;
        }

        public DxsVertex(int vid, Vector3 position, Vector2 texCoord, Vector2 lightmapCoord, Color vertexColor, int jointID) {
            ID = vid;
            Position = position;
            Normal = Vector3.Zero;
            TextureCoordinate = texCoord;
            LightMapCoordinate = lightmapCoord;
            VertexColor = vertexColor;
            JointID = jointID;
        }

        public DxsVertex(int vid, Vector3 position, Vector2 texCoord, Vector2 lightmapCoord, int jointID) {
            ID = vid;
            Position = position;
            Normal = Vector3.Zero;
            TextureCoordinate = texCoord;
            LightMapCoordinate = lightmapCoord;
            VertexColor = Color.White;
            JointID = jointID;
        }

        public DxsVertex(int vid, Vector3 position, int jointID) {
            ID = vid;
            Position = position;
            Normal = Vector3.Zero;
            TextureCoordinate = Vector2.Zero;
            LightMapCoordinate = Vector2.Zero;
            VertexColor = Color.White;
            JointID = jointID;
        }

        public DxsVertex(DxsVertex vertex) {
            ID = vertex.ID;
            Position = vertex.Position;
            Normal = vertex.Normal;
            TextureCoordinate = vertex.TextureCoordinate;
            LightMapCoordinate = vertex.LightMapCoordinate;
            VertexColor = vertex.VertexColor;
            JointID = vertex.JointID;
        }

        public override bool Equals(object obj) {
            if(obj is DxsVertex) {
                return this == (DxsVertex) obj;
            } else {
                return false;
            }
        }

        public override int GetHashCode() {
            return ID.GetHashCode() + Position.GetHashCode() + Normal.GetHashCode() + TextureCoordinate.GetHashCode() + LightMapCoordinate.GetHashCode() + VertexColor.GetHashCode()
                + JointID.GetHashCode();
        }

        public static bool operator==(DxsVertex value1, DxsVertex value2) {
            if(value1.ID == value2.ID
                && value1.Position == value2.Position
                && value1.Normal == value2.Normal
                && value1.TextureCoordinate == value2.TextureCoordinate
                && value1.LightMapCoordinate == value2.LightMapCoordinate
                && value1.JointID == value2.JointID
                && value1.VertexColor == value2.VertexColor) {
                return true;
            } else {
                return false;
            }
        }

        public static bool operator!=(DxsVertex value1, DxsVertex value2) {
            if(value1.ID != value2.ID
                || value1.Position != value2.Position
                || value1.Normal != value2.Normal
                || value1.TextureCoordinate != value2.TextureCoordinate
                || value1.LightMapCoordinate != value2.LightMapCoordinate
                || value1.JointID != value2.JointID
                || value1.VertexColor != value2.VertexColor) {
                return true;
            } else {
                return false;
            }
        }

        public override string ToString() {
            return String.Format("vid = {0} | pos = {1} | uv0 = {2}", ID.ToString(), Position.ToString(),
                TextureCoordinate.ToString());
        }
    }
}
